home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_box_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  12KB  |  346 lines

  1. #include "ewl_test.h"
  2.  
  3. static Ewl_Widget *box_button = NULL;
  4.  
  5. static void
  6. __destroy_box_test_window(Ewl_Widget * w, void *ev_data __UNUSED__, 
  7.                     void *user_data __UNUSED__)
  8. {
  9.     ewl_widget_destroy(w);
  10.     ewl_callback_append(box_button, EWL_CALLBACK_CLICKED,
  11.                 __create_box_test_window, NULL);
  12. }
  13.  
  14. static void
  15. __toggle_child_fill(Ewl_Widget * w, void *ev_data __UNUSED__, 
  16.                     void *user_data __UNUSED__)
  17. {
  18.     unsigned int f;
  19.  
  20.     f = ewl_object_fill_policy_get(EWL_OBJECT(w));
  21.  
  22.     if (f == EWL_FLAG_FILL_NONE) {
  23.         ewl_button_label_set(EWL_BUTTON(w), "Fill");
  24.         ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_FILL);
  25.     } else {
  26.         ewl_button_label_set(EWL_BUTTON(w), "None");
  27.         ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_NONE);
  28.     }
  29. }
  30.  
  31. static void
  32. __toggle_child_shrink(Ewl_Widget * w, void *ev_data __UNUSED__, 
  33.                     void *user_data __UNUSED__)
  34. {
  35.     unsigned int f;
  36.  
  37.     f = ewl_object_fill_policy_get(EWL_OBJECT(w));
  38.  
  39.     if (f == EWL_FLAG_FILL_NONE) {
  40.         ewl_object_fill_policy_set(EWL_OBJECT(w),
  41.                        EWL_FLAG_FILL_HSHRINK);
  42.         ewl_button_label_set(EWL_BUTTON(w),
  43.                      "Shrink This Box To Fit It's Parent");
  44.     } else {
  45.         ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_NONE);
  46.         ewl_button_label_set(EWL_BUTTON(w),
  47.                      "Don't shrink this box at all");
  48.     }
  49. }
  50.  
  51. static void
  52. __toggle_child_horizontal_align(Ewl_Widget * w, void *ev_data __UNUSED__, 
  53.                     void *user_data __UNUSED__)
  54. {
  55.     unsigned int   a;
  56.     char            l[10];
  57.  
  58.     a = ewl_object_alignment_get(EWL_OBJECT(w));
  59.  
  60.     if (a == EWL_FLAG_ALIGN_LEFT) {
  61.         a = EWL_FLAG_ALIGN_CENTER;
  62.         snprintf(l, 10, "Center");
  63.     } else if (a == EWL_FLAG_ALIGN_CENTER) {
  64.         a = EWL_FLAG_ALIGN_RIGHT;
  65.         snprintf(l, 10, "Right");
  66.     } else if (a == EWL_FLAG_ALIGN_RIGHT) {
  67.         a = EWL_FLAG_ALIGN_LEFT;
  68.         snprintf(l, 10, "Left");
  69.     }
  70.  
  71.     ewl_button_label_set(EWL_BUTTON(w), l);
  72.     ewl_object_alignment_set(EWL_OBJECT(w), a);
  73. }
  74.  
  75. static void
  76. __toggle_child_vertical_align(Ewl_Widget * w, void *ev_data __UNUSED__, 
  77.                         void *user_data __UNUSED__)
  78. {
  79.     unsigned int   a;
  80.     char            l[10];
  81.  
  82.     a = ewl_object_alignment_get(EWL_OBJECT(w));
  83.  
  84.     if (a == EWL_FLAG_ALIGN_TOP) {
  85.         a = EWL_FLAG_ALIGN_CENTER;
  86.         snprintf(l, 10, "Center");
  87.     } else if (a == EWL_FLAG_ALIGN_CENTER) {
  88.         a = EWL_FLAG_ALIGN_BOTTOM;
  89.         snprintf(l, 10, "Bottom");
  90.     } else if (a == EWL_FLAG_ALIGN_BOTTOM) {
  91.         a = EWL_FLAG_ALIGN_TOP;
  92.         snprintf(l, 10, "Top");
  93.     }
  94.  
  95.     ewl_button_label_set(EWL_BUTTON(w), l);
  96.     ewl_object_alignment_set(EWL_OBJECT(w), a);
  97. }
  98.  
  99. void
  100. __create_box_test_window(Ewl_Widget * w, void *ev_data __UNUSED__, 
  101.                     void *user_data __UNUSED__)
  102. {
  103.     Ewl_Widget     *box_win;
  104.     Ewl_Widget     *box_box;
  105.     Ewl_Widget     *vbox[2];
  106.     Ewl_Widget     *vbox_button[2][3];
  107.     Ewl_Widget     *hbox[3];
  108.     Ewl_Widget     *hbox_button[2][3];
  109.  
  110.     box_button = w;
  111.  
  112.     box_win = ewl_window_new();
  113.     ewl_window_title_set(EWL_WINDOW(box_win), "Box Packing Test");
  114.     ewl_window_name_set(EWL_WINDOW(box_win), "EWL Test Application");
  115.     ewl_window_class_set(EWL_WINDOW(box_win), "EFL Test Application");
  116.     ewl_object_size_request(EWL_OBJECT(box_win), 256, 256);
  117.  
  118.     if (w) {
  119.         ewl_callback_del(w, EWL_CALLBACK_CLICKED, 
  120.                     __create_box_test_window);
  121.         ewl_callback_append(box_win, EWL_CALLBACK_DELETE_WINDOW,
  122.                     __destroy_box_test_window, NULL);
  123.     } else
  124.         ewl_callback_append(box_win, EWL_CALLBACK_DELETE_WINDOW,
  125.                     __close_main_window, NULL);
  126.     ewl_widget_show(box_win);
  127.  
  128.     /*
  129.      * Create the main box for holding the widgets
  130.      */
  131.     box_box = ewl_vbox_new();
  132.     ewl_container_child_append(EWL_CONTAINER(box_win), box_box);
  133.     ewl_widget_show(box_box);
  134.  
  135.     /*
  136.      * Create the first horizontal box, this is positioned in the upper
  137.      * left corner.
  138.      */
  139.     hbox[0] = ewl_hbox_new();
  140.     ewl_container_child_append(EWL_CONTAINER(box_box), hbox[0]);
  141.     ewl_widget_show(hbox[0]);
  142.  
  143.     /******************************************************************/
  144.     /* Create a box for holding the horizontal alignment test buttons */
  145.     /******************************************************************/
  146.     vbox[0] = ewl_vbox_new();
  147.     ewl_container_child_append(EWL_CONTAINER(hbox[0]), vbox[0]);
  148.     ewl_widget_show(vbox[0]);
  149.  
  150.     /*
  151.      * Create and setup the button that starts in the left position.
  152.      */
  153.     vbox_button[0][0] = ewl_button_new();
  154.     ewl_button_label_set(EWL_BUTTON(vbox_button[0][0]), "Left");
  155.     ewl_container_child_append(EWL_CONTAINER(vbox[0]), vbox_button[0][0]);
  156.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[0][0]),
  157.                    EWL_FLAG_FILL_NONE);
  158.     ewl_object_alignment_set(EWL_OBJECT(vbox_button[0][0]),
  159.                  EWL_FLAG_ALIGN_LEFT);
  160.     ewl_callback_append(vbox_button[0][0], EWL_CALLBACK_CLICKED,
  161.                 __toggle_child_horizontal_align, NULL);
  162.     ewl_widget_show(vbox_button[0][0]);
  163.  
  164.     /*
  165.      * Create and setup the button that starts in the center position.
  166.      */
  167.     vbox_button[0][1] = ewl_button_new();
  168.     ewl_button_label_set(EWL_BUTTON(vbox_button[0][1]), "Center");
  169.     ewl_container_child_append(EWL_CONTAINER(vbox[0]), vbox_button[0][1]);
  170.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[0][1]),
  171.                    EWL_FLAG_FILL_NONE);
  172.     ewl_object_alignment_set(EWL_OBJECT(vbox_button[0][1]),
  173.                  EWL_FLAG_ALIGN_CENTER);
  174.     ewl_callback_append(vbox_button[0][1], EWL_CALLBACK_CLICKED,
  175.                 __toggle_child_horizontal_align, NULL);
  176.     ewl_widget_show(vbox_button[0][1]);
  177.  
  178.     /*
  179.      * Create and setup the button that starts in the right position.
  180.      */
  181.     vbox_button[0][2] = ewl_button_new();
  182.     ewl_button_label_set(EWL_BUTTON(vbox_button[0][2]), "Right");
  183.     ewl_container_child_append(EWL_CONTAINER(vbox[0]), vbox_button[0][2]);
  184.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[0][2]),
  185.                    EWL_FLAG_FILL_NONE);
  186.     ewl_object_alignment_set(EWL_OBJECT(vbox_button[0][2]),
  187.                  EWL_FLAG_ALIGN_RIGHT);
  188.     ewl_callback_append(vbox_button[0][2], EWL_CALLBACK_CLICKED,
  189.                 __toggle_child_horizontal_align, NULL);
  190.     ewl_widget_show(vbox_button[0][2]);
  191.  
  192.     /****************************************************************/
  193.     /* Create a box for holding the Fill test buttons               */
  194.     /****************************************************************/
  195.     vbox[1] = ewl_vbox_new();
  196.     ewl_container_child_append(EWL_CONTAINER(hbox[0]), vbox[1]);
  197.     ewl_widget_show(vbox[1]);
  198.  
  199.     /*
  200.      * Create and setup a button with no filling by default.
  201.      */
  202.     vbox_button[1][0] = ewl_button_new();
  203.     ewl_button_label_set(EWL_BUTTON(vbox_button[1][0]), "None");
  204.     ewl_container_child_append(EWL_CONTAINER(vbox[1]), vbox_button[1][0]);
  205.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[1][0]),
  206.                    EWL_FLAG_FILL_NONE);
  207.     ewl_box_orientation_set(EWL_BOX(vbox_button[1][0]),
  208.             EWL_ORIENTATION_VERTICAL);
  209.     ewl_object_alignment_set(EWL_OBJECT(EWL_BUTTON(vbox_button[1][0])->label_object),
  210.                  EWL_FLAG_ALIGN_CENTER);
  211.     ewl_callback_append(vbox_button[1][0], EWL_CALLBACK_CLICKED,
  212.                 __toggle_child_fill, NULL);
  213.     ewl_widget_show(vbox_button[1][0]);
  214.  
  215.     /*
  216.      * Create and setup a button with filling by default.
  217.      */
  218.     vbox_button[1][1] = ewl_button_new();
  219.     ewl_button_label_set(EWL_BUTTON(vbox_button[1][1]), "Fill");
  220.     ewl_container_child_append(EWL_CONTAINER(vbox[1]), vbox_button[1][1]);
  221.     ewl_box_orientation_set(EWL_BOX(vbox_button[1][1]),
  222.             EWL_ORIENTATION_VERTICAL);
  223.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[1][1]),
  224.                    EWL_FLAG_FILL_FILL);
  225.     ewl_object_alignment_set(EWL_OBJECT(EWL_BUTTON(vbox_button[1][1])->label_object),
  226.                  EWL_FLAG_ALIGN_CENTER);
  227.     ewl_callback_append(vbox_button[1][1], EWL_CALLBACK_CLICKED,
  228.                 __toggle_child_fill, NULL);
  229.     ewl_widget_show(vbox_button[1][1]);
  230.  
  231.     /*
  232.      * Create and setup a button with no filling by default.
  233.      */
  234.     vbox_button[1][2] = ewl_button_new();
  235.     ewl_button_label_set(EWL_BUTTON(vbox_button[1][2]), "None");
  236.     ewl_container_child_append(EWL_CONTAINER(vbox[1]), vbox_button[1][2]);
  237.     ewl_box_orientation_set(EWL_BOX(vbox_button[1][2]),
  238.             EWL_ORIENTATION_VERTICAL);
  239.     ewl_object_fill_policy_set(EWL_OBJECT(vbox_button[1][2]),
  240.                    EWL_FLAG_FILL_NONE);
  241.     ewl_object_alignment_set(EWL_OBJECT(EWL_BUTTON(vbox_button[1][2])->label_object),
  242.                  EWL_FLAG_ALIGN_CENTER);
  243.     ewl_callback_append(vbox_button[1][2], EWL_CALLBACK_CLICKED,
  244.                 __toggle_child_fill, NULL);
  245.     ewl_widget_show(vbox_button[1][2]);
  246.  
  247.     /****************************************************************/
  248.     /* Create a box for holding the vertical alignment test buttons */
  249.     /****************************************************************/
  250.     hbox[1] = ewl_hbox_new();
  251.     ewl_container_child_append(EWL_CONTAINER(box_box), hbox[1]);
  252.     ewl_widget_show(hbox[1]);
  253.  
  254.     /*
  255.      * Create and setup a button with top alignment by default.
  256.      */
  257.     hbox_button[0][0] = ewl_button_new();
  258.     ewl_button_label_set(EWL_BUTTON(hbox_button[0][0]), "Top");
  259.     ewl_container_child_append(EWL_CONTAINER(hbox[1]), hbox_button[0][0]);
  260.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[0][0]),
  261.                    EWL_FLAG_FILL_NONE);
  262.     ewl_object_alignment_set(EWL_OBJECT(hbox_button[0][0]),
  263.                  EWL_FLAG_ALIGN_TOP);
  264.     ewl_callback_append(hbox_button[0][0], EWL_CALLBACK_CLICKED,
  265.                 __toggle_child_vertical_align, NULL);
  266.     ewl_widget_show(hbox_button[0][0]);
  267.  
  268.     /*
  269.      * Create and setup a button with center alignment by default.
  270.      */
  271.     hbox_button[0][1] = ewl_button_new();
  272.     ewl_button_label_set(EWL_BUTTON(hbox_button[0][1]), "Center");
  273.     ewl_container_child_append(EWL_CONTAINER(hbox[1]), hbox_button[0][1]);
  274.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[0][1]),
  275.                    EWL_FLAG_FILL_NONE);
  276.     ewl_object_alignment_set(EWL_OBJECT(hbox_button[0][1]),
  277.                  EWL_FLAG_ALIGN_CENTER);
  278.     ewl_callback_append(hbox_button[0][1], EWL_CALLBACK_CLICKED,
  279.                 __toggle_child_vertical_align, NULL);
  280.     ewl_widget_show(hbox_button[0][1]);
  281.  
  282.     /*
  283.      * Create and setup a button with bottom alignment by default.
  284.      */
  285.     hbox_button[0][2] = ewl_button_new();
  286.     ewl_button_label_set(EWL_BUTTON(hbox_button[0][2]), "Bottom");
  287.     ewl_container_child_append(EWL_CONTAINER(hbox[1]), hbox_button[0][2]);
  288.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[0][2]),
  289.                    EWL_FLAG_FILL_NONE);
  290.     ewl_object_alignment_set(EWL_OBJECT(hbox_button[0][2]),
  291.                  EWL_FLAG_ALIGN_BOTTOM);
  292.     ewl_callback_append(hbox_button[0][2], EWL_CALLBACK_CLICKED,
  293.                 __toggle_child_vertical_align, NULL);
  294.     ewl_widget_show(hbox_button[0][2]);
  295.  
  296.     /****************************************************************/
  297.     /* Create a box for holding the Shrink test buttons             */
  298.     /****************************************************************/
  299.     hbox[2] = ewl_hbox_new();
  300.     ewl_container_child_append(EWL_CONTAINER(box_box), hbox[2]);
  301.     ewl_object_fill_policy_set(EWL_OBJECT(hbox[2]), EWL_FLAG_FILL_HFILL);
  302.     ewl_widget_show(hbox[2]);
  303.  
  304.     /*
  305.      * Create and setup a button with no filling by default.
  306.      */
  307.     hbox_button[1][0] = ewl_button_new();
  308.     ewl_button_label_set(EWL_BUTTON(hbox_button[1][0]),
  309.                  "Shrink This Box To Fit It's Parent");
  310.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[1][0]),
  311.                    EWL_FLAG_FILL_HSHRINK);
  312.     ewl_container_child_append(EWL_CONTAINER(hbox[2]), hbox_button[1][0]);
  313.     ewl_callback_append(hbox_button[1][0], EWL_CALLBACK_CLICKED,
  314.                 __toggle_child_shrink, NULL);
  315.     ewl_widget_show(hbox_button[1][0]);
  316.  
  317.     /*
  318.      * Create and setup a button with shrinking by default.
  319.      */
  320.     hbox_button[1][1] = ewl_button_new();
  321.     ewl_button_label_set(EWL_BUTTON(hbox_button[1][1]),
  322.                  "Shrink This Box To Fit It's Parent");
  323.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[1][1]),
  324.                    EWL_FLAG_FILL_HSHRINK);
  325.     ewl_container_child_append(EWL_CONTAINER(hbox[2]), hbox_button[1][1]);
  326.     ewl_callback_append(hbox_button[1][1], EWL_CALLBACK_CLICKED,
  327.                 __toggle_child_shrink, NULL);
  328.     ewl_widget_show(hbox_button[1][1]);
  329.  
  330.     /*
  331.      * Create and setup a button with no filling by default.
  332.      */
  333.     hbox_button[1][2] = ewl_button_new();
  334.     ewl_button_label_set(EWL_BUTTON(hbox_button[1][2]),
  335.                  "Don't shrink this box at all");
  336.     ewl_object_fill_policy_set(EWL_OBJECT(hbox_button[1][2]),
  337.                    EWL_FLAG_FILL_NONE);
  338.     ewl_container_child_append(EWL_CONTAINER(hbox[2]), hbox_button[1][2]);
  339.     ewl_callback_append(hbox_button[1][2], EWL_CALLBACK_CLICKED,
  340.                 __toggle_child_shrink, NULL);
  341.     ewl_widget_show(hbox_button[1][2]);
  342.  
  343.     return;
  344. }
  345.  
  346.